from flask import Flask, request
from recognize import human_anime
from alibabacloud_facebody20191230.models import GenerateHumanAnimeStyleResponseBody

app = Flask(__name__)


@app.route('/api/anime', methods=['post'])
def get_human_anime():
    '''
    AlgoType可以取如下值：
    anime: 日漫风
    3d: 3D特效
    handdrawn: 手绘风
    sketch: 铅笔画
    artstyle: 艺术特效
    :return:
    '''
    image_url = request.form.get('ImageURL')
    algo_type = request.form.get('AlgoType')
    res = human_anime(image_url, algo_type)
    if res and isinstance(res, GenerateHumanAnimeStyleResponseBody):
        return res.to_map()
    if res and isinstance(res, Exception):
        return res
    return {'code': 500, 'msg': '未知错误！请联系我们'}


if __name__ == '__main__':
    app.run(host='0.0.0.0')
